package com.heifeng.cloudshelf.mvp.programme.adapter;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.heifeng.cloudshelf.R;
import com.heifeng.cloudshelf.mvp.model.ProgrammeSelectInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/9/14.
 */

public class ProgrammeBottomRvAdapter extends BaseQuickAdapter<ProgrammeSelectInfo, BaseViewHolder> {
    private LinearLayoutManager layoutManager;

    private ProgrammeBottomStringRvAdapter adapter;

    private List<ProgrammeSelectInfo> data;

    private List<String> tempData = new ArrayList<>();

    public ProgrammeBottomRvAdapter(Context context, int layoutResId, @Nullable List<ProgrammeSelectInfo> data) {
        super(layoutResId, data);
        mContext = context;
        this.data = data;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, ProgrammeSelectInfo item) {
        helper.setImageResource(R.id.iv_icon, item.getIcon());
        helper.setText(R.id.tv_title, item.getTitle());
        initRecyclerView((RecyclerView) helper.getView(R.id.recyclerview), helper.getPosition());
    }

    public void initRecyclerView(RecyclerView recyclerView, int position) {
        layoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
        recyclerView.setLayoutManager(layoutManager);
        adapter = new ProgrammeBottomStringRvAdapter(mContext, R.layout.layout_programme_bottom_string_item, getTempData(data.get(position).getOptions()),data,position);

        recyclerView.setAdapter(adapter);
    }

    private List<String> getTempData(List<ProgrammeSelectInfo.OptionBean> options) {
        tempData.clear();
        if (options.size() > 0) {
            if (options.size() > 8) {
                for (int i = 0; i < 8; i++) {
                    tempData.add(options.get(i).getSpec_name());
                }
                tempData.add("更多");
            }else{
                for (int i = 0; i < options.size(); i++) {
                    tempData.add(options.get(i).getSpec_name());
                }
            }
        }
        return tempData;
    }

//    public List<String> getTempData(List<String> data1) {
//        tempData.clear();
//        if (data1.size() > 8) {
//            for (int i = 0; i < 8; i++) {
//                tempData.add(data1.get(i));
//            }
//            tempData.add("更多");
//
//            return tempData;
//        } else {
//            return data1;
//        }
//
//    }
}
